<template>
  <div class="zz-inverting-storages-search-compontent">
    <a-row :gutter="6">
      <a-col :md="12" :sm="24">
        <a-select v-model="form.Areaid" style="width:100%;" placeholder="请选择库区" @change="onAreaChange">
          <a-select-option v-for="(item,index) in areas" :key="'area-sel-'+index" :value="item.id">{{item.areaName}}</a-select-option>
        </a-select>
      </a-col>
      <a-col :md="12" :sm="24">
        <a-select v-model="form.Rowno" style="width:100%;" placeholder="请选择排" allowClear @change="onRowChange">
          <a-select-option v-for="(item,index) in rows" :key="'row-sel-'+index" :value="item">{{item}}</a-select-option>
        </a-select>
      </a-col>
    </a-row>
  </div>
</template>

<script>
import { GetArea, GetPalceRowno } from '@/api/modular/main/LocationViewManage'
export default {
  name:'zzInvertingStorageSearchCompontent',
  emits:['change'],
  props:{
    areas:{
      type:Array,
      default:function(){
        return []
      }
    },
    rows:{
      type:Array,
      default:function(){
        return []
      }
    }
  },
  data(){
    return {
      form:{
        Areaid :undefined,
        Rowno:undefined
      },
      selectList:{
        areas:[],
        rows:[]
      }
    }
  },
  methods:{
    setAreaValue(val){
      this.form.Areaid = val
    },
    setRowValue(val){
      this.form.Rowno = val
    },
    onAreaChange(val){
      this.$emit('change','area',val)
    },
    onRowChange(val){
      this.$emit('change','row',val)
    },
    getValues(){
      return {...this.form}
    }
    /* init(callback){
      this.getSelectListAreas((f1)=>{
        if (f1) {
          this.getSelectListRows((f2)=>{
            if (f2) {
              callback && callback(true,{...this.form})
            } else {
              callback && callback(false)
            }
          })
        } else {
          callback && callback(false)
        }
      })
    },
    getSelectListAreas(callback){
      GetArea().then((d)=>{
        this.selectList.areas = d.data || [];
        if (this.selectList.areas.length>0) {
          this.form.Areaid = this.selectList.areas[0].id
          callback && callback(true)
        } else {
          callback && callback(false)
        }
      }).catch(()=>{
        callback && callback(false)
      })
    },
    getSelectListRows(callback){
      let params = {Areaid:this.form.Areaid}
      GetPalceRowno(params).then((d)=>{
        this.selectList.rows = d.data || [];
        if (this.selectList.rows.length>0) {
          if (this.selectList.rows.length===1) {
            this.form.Rowno = this.selectList.rows[0]
          } else {
            this.form.Rowno = null
          }
          callback && callback(true)
        } else {
          this.form.Rowno = null
          callback && callback(false)
        }
      }).catch(()=>{
        this.selectList.rows = []
        this.form.Rowno = null
        callback && callback(false)
      })
    },
    onAreaChange() {
      this.$loading.show()
      this.getSelectListRows(()=>{
         this.$loading.hide()
      })
    },
    onSearch(){
      if (!this.form.Areaid) {
        this.$error({
          title: '系统提示',
          content: '请选择库区！',
        });
        return false;
      }
      this.$emit('search',{...this.form})
    } */
  }
}
</script>

<style lang="less" scoped>

</style>